<template>
	<view class="page">
		<!-- 订单tab -->
		<view class="order-tab">
			<view class="tab" :class="{'action':OrderType==0}" @click="onOrderTab(0)">
				<text>全部</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==1}" @click="onOrderTab(1)">
				<text>充值</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==3}" @click="onOrderTab(3)">
				<text>提现</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==33}" @click="onOrderTab(33)">
				<text>冻结</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==20}" @click="onOrderTab(20)">
				<text>结算</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==10}" @click="onOrderTab(10)">
				<text>佣金</text>
				<text class="line"></text>
			</view>
		</view>
		<!-- 订单列表 -->
		<view class="order-list">
			<!--view class="title">
				<text>日期</text>
				<text>类型</text>
				<text>金额</text>
				<text>余额</text>
			</view-->
			<view class="order-li" v-for="(item,index) in MoneyList" :key="index">
				<view class="order-number">
					<view class="number">
						<text>说明：{{item.info}}</text>
					</view>
					<!--view class="type">
						<text>{{item.sub_account}}</text>
						<text class="red">{{item.status_text}}</text>
					</view-->
				</view>
				<view class="goods-list">
					<view class="list">
						<view class="info">
							<text class="big">发生金额</text>
							<text class='green' :class="{'red':item.affect>0}">{{calculate(item.affect)}}元</text>
						</view>
						<view class="info">
							<text class="big">账户余额</text>
							<text>{{calculate(item.account)}}元</text>
						</view>
						<view class="info">
							<text class="big">发生时间</text>
							<text>{{item.happend_time}}</text>
						</view>
					</view>
				</view>
				<view class="order-status">
					<view class="switch-setting">
						<text>类型：</text>
						<text class="icon">{{item.type_name}}</text>
					</view>
					<view class="status">
						<text>日期：</text>
						<text>{{item.happend_date}}</text>
					</view>
					
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	var loginRes;
	export default {
		data() {
			return {
				OrderType: 0,
				renewal: 1,//自动续期状态
				MoneyList:[],
			};
		},
		onLoad() {
			//this.OrderType = params.type;
			loginRes = this.checkLogin();
			if(!loginRes){return;}
			//console.log(loginRes);
			this.token = loginRes[2];
			this.myMobile = loginRes[1];
			this.getMoneyList(this.token,this.OrderType,1);//获取子账号信息
		},
		methods:{
			/**
			 * 订单tab切换状态
			 * @param {Number} type
			 */
			onOrderTab(type){
				this.OrderType = type;
				this.getMoneyList(this.token,type,1);//获取子账号信息
			},
			/*获取操盘信息*/
			async getMoneyList(token,keyword,page){
				//uni.showLoading({title:"加载中",icon:"loading"});
				this.MoneyList = '';
				if(keyword==0)keyword='';
				uni.request({
					url: this.apiServer+'/apicom/moneylog?page='+page,
					header: {'content-type' : "application/x-www-form-urlencoded"},
					method: 'POST',
					timeout: 20000,
					data:{
						_search_field : "type",
						keyword : keyword,
						token   : token,
					},
					success: res => {
						//uni.hideLoading();
						if(res.data.status==1){
							var list = res.data.data;
							this.MoneyList = list;
							//console.log(res.data.data);
						}
					},
					fail:function(e){
						//uni.hideLoading();
						uni.showToast({title:"加载失败!",icon:"none"});
					}
				});
			},
			/*计算单位*/
			calculate(number){
				number = parseInt(number);
				if(number==0 || !number)return 0;
				if(number.toString().length >= 13){
					var unit = (number/1000000000000).toFixed(2);
					return unit + '万亿';
				}else if(number.toString().length >= 9){
					var unit = (number/100000000).toFixed(2);
					return unit + '亿';
				}else if(number.toString().length > 4){
					var unit =  (number/10000).toFixed(2);
					return unit + '万';
				}else{
					var unit =  number.toFixed(2);
					return unit;
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'MoneyLog.scss';
</style>
